//
//  UIBarButtonItem+Jeask.m
//  ShellTalk_iOS
//
//  Created by Jeask on 15/3/10.
//  Copyright (c) 2015年 apple. All rights reserved.
//

#import "UIBarButtonItem+Jeask.h"
#import "Header.h"

@implementation UIBarButtonItem (Jeask)

+(UIBarButtonItem *)setupBarButtonItemWithText:(NSString *)text
                                          Font:(NSInteger)font
                                        Target:(id)target
                                        action:(SEL)action
{
    CGFloat btnW = [text inquireSizeWithFont:font Widths:MAXFLOAT Heights:font].size.width;
    UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, btnW + 10, font)];
    button.titleLabel.font = [UIFont systemFontOfSize:font];
    [button setTitleColor:[UIColor whiteColor]forState:0];
    [button setTitle:text forState:0];
    [button addTarget:target action:action forControlEvents:1<<6];
    
    UIBarButtonItem *barItem = [[UIBarButtonItem alloc] initWithCustomView:button];
    return barItem;
}


+(UIBarButtonItem *)setupBarButtonItemWithNormalIcon:(NSString *)normalIcon
                                               Scale:(CGFloat)scale
                                              Target:(id)target
                                              Action:(SEL)action
{
    UIImage *icon = [UIImage imageWithName:normalIcon Factor:scale];
    return [[UIBarButtonItem alloc] initWithImage:icon style:UIBarButtonItemStylePlain target:target action:action];
}


+(UIBarButtonItem *)setupCustomBarButtonItemWithNormalIcon:(NSString *)normalIcon
                                                     Scale:(CGFloat)scale
                                                    Target:(id)target
                                                    Action:(SEL)action{
    
    UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 35, 35)];
    [button setImage:[UIImage imageWithName:normalIcon Factor:scale] forState:0];
    [button addTarget:target action:action forControlEvents:1<<6];
    
    return [[UIBarButtonItem alloc] initWithCustomView:button];
}

+(void)setupBackButtonStart
{
    [[UIBarButtonItem appearance] setBackButtonTitlePositionAdjustment:UIOffsetMake(0, -60)
                                                         forBarMetrics:UIBarMetricsDefault];
}

+(void)setupBackButtonDismiss
{
    [[UIBarButtonItem appearance] setBackButtonTitlePositionAdjustment:UIOffsetMake(0, 0)
                                                         forBarMetrics:UIBarMetricsDefault];
}

+ (UIBarButtonItem *)itemWithTarget:(id)target action:(SEL)action image:(NSString *)image highImage:(NSString *)highImage
{
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
    [btn addTarget:target action:action forControlEvents:UIControlEventTouchUpInside];
    [btn setBackgroundImage:[UIImage imageNamed:image] forState:UIControlStateNormal];
    [btn setBackgroundImage:[UIImage imageNamed:highImage] forState:UIControlStateHighlighted];
    btn.size = btn.currentBackgroundImage.size;
    return [[UIBarButtonItem alloc] initWithCustomView:btn];
}


+ (UIBarButtonItem *)createRightPublishBtnWithImage:(NSString *)image size:(CGRect)rect target:(id)target action:(SEL)action
{
    UIButton *rightBtn = [[UIButton alloc] init];
    UIImage *cimage = [UIImage imageNamed:image];
    [cimage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    [rightBtn setImage:cimage forState:UIControlStateNormal];
    rightBtn.frame = CGRectMake(10, 10, 20, 20);
    [rightBtn addTarget:target action:action forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem *barBtn = [[UIBarButtonItem alloc] initWithCustomView:rightBtn];
    return barBtn;
}


@end

